;:::::::::::::::::::::::::::::::::
; SRC.TEXT (COMAL MODULE)        :
;                                :
; BY M.BOKHORST, NOV85           :
; REVISED BY D.KLINGENS          :
;                                :
; DUTCH COMAL USERS GROUP        :
;:::::::::::::::::::::::::::::::::
;
;-- VARIABLES & CONSTANTS --
;
DEFPAG = %01000110
DUMMY = $CA2F
PROC = 112
ENDPRC = 126
FUNC = 227
ENDFNC = 126
PSHINT = $C9CE
STR = 2
REF = 117
POINT = $FB
FNDPAR = $C896
COPY1 = $45
COPY2 = $47
COPY3 = $49
COPYDN = $C8A2
RUNERR = $C9FB
;
;-- MODULE --
;
* = $8009
;
 .BYTE DEFPAG
EINDE .WORD END
 .WORD DUMMY
 .BYTE 4,'TEXT'
 .WORD PROCS
 .WORD RESET
 .BYTE 0
;
;-- PROCEDURES & FUNCTIONS --
;
PROCS .BYTE 7,'REWRITE'
 .WORD HEMPTY
 .BYTE 7,'WRITELN'                       .WORD HPUT
 .WORD HPUT
 .BYTE 6,'READLN'
 .WORD HGET
 .BYTE 5,'RESET'
 .WORD HRES
 .BYTE 3,'EOT'
 .WORD HEOT
 .BYTE 0
;
;-- HEADERS --
;
HEMPTY .BYTE PROC
 .WORD EMPTY
 .BYTE 0
 .BYTE ENDPRC
;
HPUT .BYTE PROC
 .WORD PUT
 .BYTE 1
 .BYTE STR+REF
 .BYTE ENDPRC
;
HGET .BYTE PROC
 .WORD GET
 .BYTE 1
 .BYTE STR+REF
 .BYTE ENDPRC
;
HRES .BYTE PROC
 .WORD RESET
 .BYTE 0
 .BYTE ENDPRC
;
HEOT .BYTE FUNC
 .WORD EOT
 .BYTE 0
 .BYTE ENDFNC
;
;-- CODE --
;
EMPTY LDA #<END
 LDY #>END
 STA EINDE
 STY EINDE+1
;
RESET LDA #<END
 LDY #>END
 STA POINT
 STY POINT+1
 RTS
;
EOT JSR TEOF
 LDA #0
 ROL A
 TAX
 LDA #0
 JMP PSHINT
;
PUT LDA #1
 JSR FNDPAR
 LDA COPY1
 CLC
 ADC #<2
 STA COPY1
 LDA COPY1+1
 ADC #>2
 STA COPY1+1
 LDA EINDE
 LDY EINDE+1
 STA COPY2
 STY COPY2+1
 LDY #1
SETUP LDA (COPY1),Y
 STA COPY3,Y
 DEY
 BPL SETUP
;
 JSR LEN
 LDA COPY3+1
 CLC
 ADC EINDE
 TAX
 LDA COPY3
 ADC EINDE+1
 CMP #$C0
 BCS OUT
 STX EINDE
 STA EINDE+1
 JMP COPYDN
;
EOF LDX #201 ;END-OF-FIL
 .BYTE $2C ;SKIP 2
OUT LDX #52 ;OUT OF MEM
 JMP RUNERR
;
TEOF LDA POINT
 SEC
 SBC EINDE
 LDA POINT+1
 SBC EINDE+1
 RTS
;
GET JSR TEOF
 BCS EOF
 LDA #1
 JSR FNDPAR
 LDA COPY1
 CLC
 ADC #<2
 STA COPY2
 LDA COPY1+1
 ADC #>2
 STA COPY2+1
 LDY #1
 LDA (COPY1),Y
 SEC
 SBC (POINT),Y
 DEY
 LDA (COPY1),Y
 SBC (POINT),Y
 BCC NOROOM
 LDA POINT
 LDY POINT+1
 STA COPY1
 STY COPY1+1
 LDY #1
SETUP1 LDA (POINT),Y
 STA COPY3,Y
 DEY
 BPL SETUP1
 JSR LEN
 LDA POINT
 CLC
 ADC COPY3+1
 STA POINT
 LDA POINT+1
 ADC COPY3
 STA POINT+1
 JMP COPY
;
NOROOM LDA (COPY1),Y
 STA COPY3
 PHA
 INY
 LDA (COPY1),Y
 STA COPY3+1
 PHA
 LDA POINT
 LDY POINT+1
 STA COPY1
 STY COPY1+1
 JSR LEN
 LDY #1
 LDA (POINT),Y
 CLC
 ADC POINT
 TAX
 DEY
 LDA (POINT),Y
 ADC POINT+1
 TAY
 TXA
 CLC
 ADC #<2
 STA POINT
 TYA
 ADC #>2
 STA POINT+1
 LDY #1
 PLA
 STA (COPY1),Y
 DEY
 PLA
 STA (COPY1),Y
;
COPY LDX COPY3
 LDA COPY3+1
 TAY
 BEQ L001
 EOR #255
 TAY
 INY
 CLC
 LDA COPY1
 ADC COPY3+1
 STA COPY1
 BCS L002
 DEC COPY1+1
L002 CLC
 LDA COPY2
 ADC COPY3+1
 STA COPY2
 BCS L003
 DEC COPY2+1
L003 LDA (COPY1),Y
 STA (COPY2),Y
 INY
 BNE L003
 INC COPY1+1
 INC COPY2+1
L001 DEX
 BPL L003
 RTS
;
LEN LDA COPY3+1
 CLC
 ADC #<2
 STA COPY3+1
 LDA COPY3
 ADC #>2
 STA COPY3
 RTS
;
END .END
